package com.cote.douhahou.pretloan.any.timezone

import android.text.TextUtils
import java.util.*

object AkomapalendTimeZoneUtil {

    private fun currentTimeZoneSupportCountryList(): List<String> {
        val list = mutableListOf<String>()
        val timeZoneId = TimeZone.getDefault().id.toString()
        println("======timeZoneId=$timeZoneId")
        when (timeZoneId) {
            AkomapalendTimeZoHostEnum.GHA.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.GHA.country)
            }
            AkomapalendTimeZoHostEnum.FCFA.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.FCFA.country)
            }
            AkomapalendTimeZoHostEnum.KSH.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.KSH.country)
            }
            AkomapalendTimeZoHostEnum.UGX.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.UGX.country)
            }
            AkomapalendTimeZoHostEnum.TANZAN.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.TANZAN.country)
            }
            AkomapalendTimeZoHostEnum.SENEGAL.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.SENEGAL.country)
            }
            AkomapalendTimeZoHostEnum.ZMB.timeZoId -> {
                list.add(AkomapalendTimeZoHostEnum.ZMB.country)
            }
        }
        return list
    }

    fun covertToRealTargetServers(list: List<String>): List<String> {
        val curTimeZoneSupportCountrys: List<String> = currentTimeZoneSupportCountryList()
        val serviceTargetUrlList = list.filter { url ->
            curTimeZoneSupportCountrys.any { country -> url.endsWith(country) }
        }
        val resultTargetUrlList = serviceTargetUrlList.ifEmpty { list }
        return resultTargetUrlList
    }

    fun timeZoneID():String{
        val result = TimeZone.getDefault().id
        if (TextUtils.isEmpty(result)) return ""
        return result
    }
}